﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevTeam;
using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class TopDuzeltmeGP : XForm
    {
        int GPId = 0;
        public TopDuzeltmeGP(int GPId)
        {
            InitializeComponent();
            this.GPId = GPId;
        }

        private void TopDuzeltmeGP_Load(object sender, EventArgs e)
        {
            gleOwner.Properties.Assign(RI(Rp.V_Customer));
            txtInfo.Caption = GPId.ToString();
            btnGuncelle.Click += btnGuncelle_Click;
        }

        void btnGuncelle_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("Emin misiniz?", "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                int ownerId = 0;

                if (txtNotes.Text.Trim().Length > 0)
                {
                    ownerId = intParse(gleOwner.EditValue);
                    if (ownerId > 0)
                    {
                        if (intParse(Session.DataManager.ExecuteScalar("InsTopDuzeltmeGP", GPId, txtNotes.Text, ownerId, WhoAmI)) > 0)
                            ShowInfoMessage("Geliş partisindeki toplar güncellendi.");

                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                    else
                        ShowErrorMessage("Yeni OwnerId girilmiş olmalı.");
                }
                else
                    ShowErrorMessage("Açıklama zorunlu alandır.");
            }
        }
    }
}
